package com.google.gwt.homepage.smile.shared;

import java.io.Serializable;


import com.google.gwt.homepage.smile.shared.ContactDetails;

@SuppressWarnings("serial")
public class EnneagramTestResultBean implements Serializable {
	
	//애니어그램 유형
	final static int TYPE_NUM = 9;
	
	final static String TypeName[]={"개혁가","조력자","동기부여자","예술가","사색가","충성가","낙천가","지도자","조정자"};
	
	
	//값 //3(동의), 2(보통), 1(반대)
	final static int AGREE = 3;
	final static int MIDIUM = 2;
	final static int REJECT = 1;
    
	
	//검사 결과를 저장할 배열(계산의 편의를 위해 크기를 +1함
	int[][] testResult = new int[TYPE_NUM+1][EnneagramQuestions.getQuestionNumForType()+1]; 
	
	
	
	public EnneagramTestResultBean() {
		//결과테이블 초기화
    	for(int i=0;i<10;i++){
    		for(int j=0;j<EnneagramQuestions.getQuestionNumForType()+1;j++){
    			testResult[i][j]=0;
    		}
    	}
	}
	

	
  public boolean isSelectedAgree(int type, int num) {
	  
	  if(testResult[type][num]==3)
		  return true;
	  else
		  return false; 
  }
  
  public boolean isSelectedMedi(int type, int num) {
	  
	  if(testResult[type][num]==2)
		  return true;
	  else
		  return false; 
  }
  
  public boolean isSelectedRej(int type, int num) {
	  
	  if(testResult[type][num]==1)
		  return true;
	  else
		  return false; 
  }
  
 public void saveResult(int type, int num, int checkedValue) {
	  
	  testResult[type][num]=checkedValue;
		 
  }
  
 public boolean getAllChecked(){
	 for(int i=1;i<10;i++){
	  		for(int j=1;j<EnneagramQuestions.getQuestionNumForType()+1;j++){
	  			if(testResult[i][j]==0){
	  				return false;
	  			}
	  		}
	  	}
	  	return true;
 }
 
 public int getQuestionNumForType(){
	 return EnneagramQuestions.getQuestionNumForType();
 }
 
 //각유형별 동의를 체크한 비율(%)
 public int[] getResultValue(){
	 int [] result= new int[TYPE_NUM];
	 System.out.println("count");
	 for(int i=1;i<TYPE_NUM+1;i++){
	  		for(int j=1;j<EnneagramQuestions.getQuestionNumForType()+1;j++){
	  			if(testResult[i][j]==AGREE){
	  				result[i-1]++;
	  				System.out.println(i+"_"+j+" : "+result[i-1]);
	  			}
	  		}
	  	}
	 for(int i=1;i<TYPE_NUM+1;i++){
		 System.out.println(i+" & "+result[i-1]+"_"+EnneagramQuestions.getQuestionNumForType());
		Double transVal=(Double.parseDouble(Integer.toString(result[i-1])) /EnneagramQuestions.getQuestionNumForType())*100;
		result[i-1]=(int)Math.round(transVal);
		System.out.println("aaaa"+result[i-1]);
  	}
	 
	 return result;
 }
 
 
 //나의 type
 public String  getMyType(){
	 int myType= 1;
	 int maxValue=0;
	 
	 int result[]=getResultValue();
	 
	 for(int i=0;i<result.length;i++){
		 if(maxValue<result[i]){
			 myType=i+1;
			 maxValue=result[i];
		 }
	 }

	 return Integer.toString(myType);
 }
 
//나의 날개
 //나의 유형의 양옆 유형중   큰 값을 가진 유형
 public String  getMyWing(){
	 int myType= Integer.parseInt(getMyType());
	 
	 
	 int left = myType==1 ? 9 : myType-1;//나의 유형의 왼쪽 유형 
	 int right = myType==9 ? 1 : myType+1;//나의 유형의 오른쪽 유형
	 
	 int result[]=getResultValue();
	 
	 if(result[left-1]>=result[right-1]){
		 return Integer.toString(left);
	 }else{
		 return Integer.toString(right);
	 }
	 
 }
 
 //각 유형의 유형명
 public String getTypeName(String Type){
	 return TypeName[Integer.parseInt(Type)-1];
 }
 
}
